package com.cy.common.security.filter;

import com.cy.common.exception.CommonException;
import com.cy.common.util.JwtUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author : 残影
 * @Date: 2021-01-22 17:33
 */
@Component
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws ServletException, IOException {
        if (JwtUtils.checkToken(request)){
            throw new CommonException("token无效");
        }
        chain.doFilter(request, response);
    }
}
